package ren.xbcr.schoolbus.client.custom.asynctask;

import android.content.Context;
import android.os.AsyncTask;
import android.util.Log;

import java.util.ArrayList;

import ren.xbcr.schoolbus.client.service.SchoolBusService;
import ren.xbcr.schoolbus.client.util.PrefUtils;
import ren.xbcr.schoolbus.client.util.SchoolArrayAdapter;

/**
 * Created by Jian on 2015/12/8.
 */
public class SchoolArrayTask extends AsyncTask<Void, Void,  ArrayList<String>> {

    private Context mContext;
    public SchoolArrayTask(Context context){

        mContext = context;
    }

    @Override
    protected ArrayList<String> doInBackground(Void... params) {
        try {
            SchoolBusService schoolBusService = new SchoolBusService();
            ArrayList<String> schools= schoolBusService.getAllSchool();
            return schools;
        } catch (Exception e) {
            Log.e("MainActivity", e.getMessage(), e);
        }

        return null;
    }

    @Override
    protected void onPostExecute( ArrayList<String> schools) {
// Create the adapter and set it to the AutoCompleteTextView

        PrefUtils.saveToPrefs(mContext, PrefUtils.PREFS_SCHOOL_NAMES, schools);
    }
}
